<template>
  <page-body>
    <view class="page">
      <view class="flex benben-position-layout flex flex-wrap align-center registerPage_flex_0"
        :style="{height:(88+StatusBarRpx)+'rpx',paddingTop:StatusBarRpx+'rpx', }">
        <view class='flex flex-wrap align-center justify-between flex-sub registerPage_fd0_0'>
          <view class='flex flex-wrap align-center registerPage_fd0_0_c0' @tap.stop="handleJumpDiy" data-type="back"
            data-url="1">
            <text class='fu-iconfont2  registerPage_fd0_0_c0_c0'>&#xE794;</text>
          </view>
          <view class='flex flex-wrap align-center justify-end registerPage_fd0_0_c0'>
          </view>
        </view>

      </view>
      <view :style="{height: (88+StatusBarRpx)+'rpx'}"></view>
      <!---flex布局flex布局开始-->
      <view class="flex flex-direction flex-wrap align-stretch benben-flex-layout registerPage_flex_1">
        <image class='registerPage_fd1_0' mode="aspectFit" :src='STATIC_URL+"63.png"'></image>
        <text class='registerPage_fd1_1'>欢迎来到梦舱</text>
      </view>

      <!---flex布局flex布局结束-->
      <!---flex布局flex布局开始-->
      <view class="flex flex-direction flex-wrap align-stretch benben-flex-layout registerPage_flex_2">
        <view class='flex flex-wrap align-center registerPage_fd2_0'>
          <image class='registerPage_fd2_0_c0' mode="aspectFit" :src='STATIC_URL+"184.png"'></image>
          <benben-input class='flex-sub registerPage_fd2_0_c1' type="number" :placeholder="`请输入手机号`" confirm-type="done"
            :maxlength="11" placeholder-style="color:#999;font-size:32rpx" v-model="mobile" />
        </view>
        <view class='flex flex-wrap align-center registerPage_fd2_1'>
          <image class='registerPage_fd2_0_c0' mode="aspectFit" :src='STATIC_URL+"78.png"'></image>
          <benben-input class='flex-sub registerPage_fd2_1_c1' type="number" :placeholder="`请输入验证码`" confirm-type="done"
            :maxlength="4" placeholder-style="color:#999;font-size:32rpx" v-model="code" />
          <benben-send-verification-code key='1710986785976' ref="vCode1710986785976" class=' registerPage_fd2_1_c2'
            after-text='后重新获取' before-text='获取验证码' emptye-text='请输入手机号' validate-text='请输入正确手机号' account-type='phone'
            :auto='true' type='1' :phone="mobile"></benben-send-verification-code>
        </view>
        <view class='flex flex-wrap align-center registerPage_fd2_2'>
          <image class='registerPage_fd2_0_c0' mode="aspectFit" :src='STATIC_URL+"185.png"'></image>
          <benben-flex-password-diy v-model="password" class-name="flex flex align-center registerPage_fd2_2_c1"
            :placeholder="'请输入密码(6~12位字母+数字)'" :maxlength="12" :default-type='true'
            placeholder-style="color:#999;font-size:32rpx">
            <template #show>
              <text class='fu-iconfont2  registerPage_fd2_2_c1_icon1' data-type="show">&#xE837;</text>
            </template>
            <template #hide>
              <text class='fu-iconfont2  registerPage_fd2_2_c1_icon1' data-type="hide">&#xEBCC;</text>
            </template>
          </benben-flex-password-diy>
        </view>
        <view class='flex flex-wrap align-center registerPage_fd2_1'>
          <image class='registerPage_fd2_0_c0' mode="aspectFit" :src='STATIC_URL+"212.png"'></image>
          <benben-input class='flex-sub registerPage_fd2_1_c1' type="text" :placeholder="`请输入邀请码`" confirm-type="done"
            :maxlength="8" placeholder-style="color:#999;font-size:32rpx" v-model="invite_code" />
        </view>
        <button class='registerPage_fd2_3' @tap.stop="registerFunc()">注册</button>
        <view class='flex flex-wrap align-center justify-center'>
          <text class='registerPage_fd2_4_c0'>已有账号，前去</text>
          <text class='registerPage_fd2_4_c1' @tap.stop="toLoginDiy()">登录</text>
        </view>
        <view class='flex flex-wrap align-center justify-center registerPage_fd2_5'>
          <benben-flex-switch-new class-name='flex flex' v-model="is_tk" :disabled='false'>
            <template v-slot:checked>

              <view class='flex flex position-relative align-center'>
                <image class='registerPage_checkfd2_5_c0_c0_c0' mode="aspectFit" :src='STATIC_URL+"38.png"'></image>
              </view>

            </template>
            <template v-slot:unchecked>

              <view class='flex flex position-relative justify-end align-center'>
                <image class='registerPage_noCheckfd2_5_c0_c1_c0' mode="aspectFit" :src='STATIC_URL+"66.png"'></image>
              </view>

            </template>
          </benben-flex-switch-new>
          <text class='registerPage_fd2_5_c1'>已阅读并同意</text>
          <text class='registerPage_fd2_5_c2' @tap.stop="handleJumpDiy" data-type="navigateTo"
            :data-url="`/pages/dlzc/agreements/agreements`">《用户注册协议》</text>
          <text class='registerPage_fd2_5_c3'>与</text>
          <text class='registerPage_fd2_5_c2' @tap.stop="handleJumpDiy" data-type="navigateTo"
            :data-url="`/pages/dlzc/privacyPolicy/privacyPolicy`">《隐私政策》</text>
        </view>
      </view>

      <!---flex布局flex布局结束-->


    </view>
  </page-body>
</template>
<script>
  // 腾讯IM
  import {
    TUIChatKit,
    genTestUserSig
  } from "@/TUIKit";
  import {
    SYSTEM_CONFIG,
    SDKAppID,
    secretKey
  } from "@/common/config.js";
  import {
    vueVersion
  } from "@/TUIKit/adapter-vue";
  import {
    TUILogin
  } from "@tencentcloud/tui-core";
  // edddddddddd
  import {
    validate
  } from '@/common/utils/validate.js'

  export default {
    components: {},


    data() {
      return {
        "mobile": "",
        "code": "",
        "password": "",
        "invite_code": "",
        "dataList": {
          "userinfo": {
            "user_token": "",
            "id": "",
            "avatar": "",
            "real_name": "",
            "nickname": "",
            "email": "",
            "gender": "",
            "mobile": "",
            "birthday": ""
          }
        },
        "is_tk": false
      };
    },
    computed: {

    },
    watch: {},
    onLoad(options) {

    },
    onUnload() {

    },
    onReady() {

    },
    onShow() {

    },
    onHide() {

    },
    onResize() {

    },
    onPullDownRefresh() {

    },
    onReachBottom(e) {

    },
    onPageScroll(e) {

    },
    methods: {
      // 聊天登录
      tUILogin(config) {
        const userSig = genTestUserSig(config).userSig;
        TUILogin.login({
          SDKAppID: config.SDKAppID,
          userID: config.userID,
          userSig: userSig,
          // 如果您需要发送图片、语音、视频、文件等富媒体消息，请设置为 true
          useUploadPlugin: true,
          useProfanityFilterPlugin: false,
          framework: `vue${vueVersion}` // 当前开发使用框架 vue2 / vue3
        }).then(() => {
          console.log('登录成功', global.userInfo)
          uni.$TIM.updateMyProfile({
            nick: global.userInfo.nickname,
            avatar: global.userInfo.avatar,
          }).then(() => {
            console.log('gengxin 成功')
          })

        })
      },
      // 聊天登录s
      //注册
      async registerFunc() {
        if (!validate(this.mobile, 'require')) {
          this.$message.info('请输入手机号');
          return false;
        }
        if (!validate(this.mobile, 'phone')) {
          this.$message.info('请输入正确的手机号');
          return false;
        }
        if (!validate(this.code, 'require')) {
          this.$message.info('请输入验证码');
          return false;
        }
        if (!validate(this.code, 'captcha')) {
          this.$message.info('请输入正确的验证码');
          return false;
        }
        if (!validate(this.password, 'require')) {
          this.$message.info('请输入密码');
          return false;
        }
        if (!validate(this.password, 'password')) {
          this.$message.info('密码格式错误');
          return false;
        }
        if (this.is_tk === false) {
          this.$message.info('请勾选协议');
          return false;
        }
        //请求方法
        //数据验证

        let datadataList = await this.$api.dbPost(global.apiUrls.post5cad9f63e4f94, {
          mobile: this.mobile,
          code: this.code,
          password: this.password,
          invite_code: this.invite_code
        });
        if (!datadataList) return
        if (datadataList.data.code != 1) {
          this.$message.info(datadataList.data.msg);
          return
        }
        let infodataList = datadataList.data;
        this.dataList = infodataList.data

        this.$store.commit('saveToken', this.dataList.userinfo.user_token)
        this.$store.commit('updateUserInfo', this.dataList.userinfo)
        // 腾讯Im
        const userID = this.dataList.userinfo ? this.dataList.userinfo.id.toString() : '';
        const config = {
          userID: userID, //User ID
          SDKAppID: SDKAppID, // Your SDKAppID
          secretKey: secretKey, // Your secretKey
        };
        this.tUILogin(config)
        uni.redirectTo({
          url: `/pages/grzx/information/information`
        })
      }
    }
  };
</script>
<style lang="scss" scoped>
  .page {
    width: 100vw;
    overflow-x: hidden;
    min-height: calc(100vh - var(--window-bottom));
    background: var(--benbenbgColor1);
    background-size: 100% auto;
  }

  .registerPage_flex_0 {
    background: url(image-path('151.png')) no-repeat;
    width: 750rpx;
    height: 88rpx;
    overflow: hidden;
    z-index: 10;
    top: 0rpx;
    background-size: 100% auto;
  }

  .registerPage_fd0_0_c0_c0 {
    font-size: 36rpx;
    color: #333;
  }

  .registerPage_fd0_0_c0 {
    width: 120rpx;
  }

  .registerPage_fd0_0 {
    padding: 0rpx 32rpx 0rpx 32rpx;
  }

  .registerPage_flex_1 {
    background: url(image-path('151.png')) no-repeat;
    padding: 80rpx 0rpx 80rpx 40rpx;
    background-size: 100% auto;
  }

  .registerPage_fd1_1 {
    color: rgba(26, 30, 41, 1);
    font-size: 48rpx;
    font-weight: 600;
    line-height: 45rpx;
    margin: 38rpx 0rpx 40rpx 0rpx;
  }

  .registerPage_fd1_0 {
    width: 88rpx;
    height: 88rpx;
    border-radius: 33rpx 33rpx 33rpx 33rpx;
  }

  .registerPage_flex_2 {
    background: var(--benbenbgColor1);
    padding: 0rpx 56rpx 100rpx 56rpx;
    background-size: 100% auto;
  }

  .registerPage_fd2_5_c3 {
    color: var(--benbenFontColor2);
    font-size: 28rpx;
    font-weight: 400;
    line-height: 33rpx;
  }

  .registerPage_fd2_5_c2 {
    color: var(--benbenFontColor4);
    font-size: 28rpx;
    font-weight: 400;
    line-height: 33rpx;
  }

  .registerPage_fd2_5_c1 {
    color: var(--benbenFontColor2);
    font-size: 28rpx;
    font-weight: 400;
    line-height: 33rpx;
    margin: 0rpx 0rpx 0rpx 16rpx;
  }

  .registerPage_noCheckfd2_5_c0_c1_c0 {
    border-radius: 24rpx 24rpx 24rpx 24rpx;
    width: 24rpx;
    height: 24rpx;
  }

  .registerPage_checkfd2_5_c0_c0_c0 {
    width: 24rpx;
    height: 24rpx;
    border-radius: 24rpx 24rpx 24rpx 24rpx;
  }

  .registerPage_fd2_5 {
    background: var(--benbenbgColor1);
    width: 750rpx;
    position: fixed;
    bottom: calc(0rpx + var(--window-bottom));
    left: 0rpx;
    height: 100rpx;
    background-size: 100% auto;
    z-index: 9;
  }

  .registerPage_fd2_4_c1 {
    color: var(--benbenFontColor4);
    font-size: 28rpx;
    font-weight: 400;
    line-height: 40rpx;
  }

  .registerPage_fd2_4_c0 {
    color: var(--benbenFontColor2);
    font-size: 28rpx;
    font-weight: 400;
    line-height: 40rpx;
  }

  .registerPage_fd2_3 {
    background: var(--benbenbgColor2);
    border-radius: 50rpx 50rpx 50rpx 50rpx;
    font-size: 32rpx;
    color: var(--benbenFontColor3);
    width: 638rpx;
    height: 88rpx;
    line-height: 88rpx;
    margin: 104rpx 0rpx 32rpx 0rpx;
  }

  .registerPage_fd2_2_c1_icon1 {
    width: 88rpx;
    line-height: 88rpx;
    text-align: center;
    font-size: 40rpx;
  }

  ::v-deep .registerPage_fd2_2_c1 {
    height: 45rpx;
    width: 510rpx;
    font-size: 32rpx;
    margin: 0rpx 0rpx 0rpx 32rpx;
  }

  .registerPage_fd2_2 {
    background: #F8F8F8;
    padding: 0rpx 16rpx 0rpx 16rpx;
    margin: 48rpx 0rpx 0rpx 0rpx;
    border-radius: 40rpx 40rpx 40rpx 40rpx;
    width: 638rpx;
    height: 80rpx;
  }

  .registerPage_fd2_1_c2 {
    line-height: 42rpx;
    text-align: center;
    font-size: 28rpx;
    color: var(--benbenFontColor4);
  }

  .registerPage_fd2_1_c1 {
    height: 80rpx;
    margin: 0rpx 0rpx 0rpx 32rpx;
    color: var(--benbenFontColor0);
    font-size: 28rpx;
    font-weight: 400;
    line-height: 80rpx;
  }

  .registerPage_fd2_1 {
    background: #F8F8F8;
    padding: 0rpx 16rpx 0rpx 16rpx;
    border-radius: 40rpx 40rpx 40rpx 40rpx;
    width: 638rpx;
    height: 80rpx;
    margin: 48rpx 0rpx 0rpx 0rpx;
  }

  .registerPage_fd2_0_c1 {
    height: 80rpx;
    margin: 0rpx 0rpx 0rpx 32rpx;
    color: var(--benbenFontColor0);
    font-size: 32rpx;
    font-weight: 400;
    line-height: 80rpx;
  }

  .registerPage_fd2_0_c0 {
    width: 34rpx;
    height: 34rpx;
    border-radius: 0rpx 0rpx 0rpx 0rpx;
  }

  .registerPage_fd2_0 {
    background: #F8F8F8;
    padding: 0rpx 16rpx 0rpx 16rpx;
    border-radius: 40rpx 40rpx 40rpx 40rpx;
    width: 638rpx;
    height: 80rpx;
  }
</style>
